﻿using System;
using System.Collections.Specialized;
using System.IO;
using System.Web;

namespace NWebMock
{
    public interface IHttpServerUtility
    {
        #region Properties

        /// <summary>
        /// Gets the server's computer name.
        /// </summary>
        string MachineName { get; }

        /// <summary>
        /// Gets and sets the request time-out value in seconds.
        /// </summary>
        int ScriptTimeout { get; set; }

        #endregion

        #region Methods

        /// <summary>
        /// Clears the previous exception.
        /// </summary>
        void ClearError();

        /// <summary>
        /// Creates a server instance of a COM object identified by the object's programmatic identifier (ProgID).
        /// </summary>
        /// <param name="progID">The class or type of object to create an instance of.</param>
        /// <returns>The new object.</returns>
        Object CreateObject(string progID);

        /// <summary>
        /// Creates a server instance of a COM object identified by the object's type.
        /// </summary>
        /// <param name="type">A Type representing the object to create.</param>
        /// <returns>The new object.</returns>
        Object CreateObject(Type type);

        /// <summary>
        /// Creates a server instance of a COM object identified by the object's class identifier (CLSID).
        /// </summary>
        /// <param name="clsid">The class identifier of the object to create an instance of.</param>
        /// <returns>The new object.</returns>
        Object CreateObjectFromClsid(string clsid);

        /// <summary>
        /// Executes the handler for the specified virtual path in the context of the current request. 
        /// </summary>
        /// <param name="path">The URL path to execute.</param>
        void Execute(string path);

        /// <summary>
        /// Executes the handler for the specified virtual path in the context of the current request and specifies whether to clear the QueryString and Form collections.
        /// </summary>
        /// <param name="path">The URL path to execute.</param>
        /// <param name="preserveForm">true to preserve the QueryString and Form collections; false to clear the QueryString and Form collections.</param>
        void Execute(string path, bool preserveForm);

        /// <summary>
        /// Executes the handler for the specified virtual path in the context of the current request. A TextWriter captures output from the executed handler.
        /// </summary>
        /// <param name="path">The URL path to execute.</param>
        /// <param name="writer">The TextWriter to capture the output.</param>
        void Execute(string path, TextWriter writer);

        /// <summary>
        /// Executes the handler for the specified virtual path in the context of the current request. A TextWriter captures output from the executed handler and a Boolean parameter specifies whether to clear the QueryString and Form collections.
        /// </summary>
        /// <param name="handler">The HTTP handler that implements the IHttpHandler to transfer the current request to.</param>
        /// <param name="writer">The TextWriter to capture the output.</param>
        /// <param name="preserveForm">true to preserve the QueryString and Form collections; false to clear the QueryString and Form collections.</param>
        void Execute(IHttpHandler handler, TextWriter writer, bool preserveForm);

        /// <summary>
        /// Executes the handler for the specified virtual path in the context of the current request. A TextWriter captures output from the page and a Boolean parameter specifies whether to clear the QueryString and Form collections.
        /// </summary>
        /// <param name="path">The URL path to execute.</param>
        /// <param name="writer">The TextWriter to capture the output.</param>
        /// <param name="preserveForm">true to preserve the QueryString and Form collections; false to clear the QueryString and Form collections.</param>
        void Execute(string path, TextWriter writer, bool preserveForm);

        /// <summary>
        /// Returns the previous exception.
        /// </summary>
        /// <returns>The previous exception that was thrown.</returns>
        Exception GetLastError();

        /// <summary>
        /// Decodes an HTML-encoded string and returns the decoded string.
        /// </summary>
        /// <param name="s">The HTML string to decode.</param>
        /// <returns>The decoded text.</returns>
        string HtmlDecode(string s);

        /// <summary>
        /// Decodes an HTML-encoded string and sends the resulting output to a TextWriter output stream.
        /// </summary>
        /// <param name="s">The HTML string to decode.</param>
        /// <param name="output">The TextWriter output stream that contains the decoded string.</param>
        void HtmlDecode(string s, TextWriter output);

        /// <summary>
        /// HTML-encodes a string and returns the encoded string.
        /// </summary>
        /// <param name="s">The text string to encode.</param>
        /// <returns>The HTML-encoded text.</returns>
        string HtmlEncode(string s);

        /// <summary>
        /// HTML-encodes a string and sends the resulting output to a TextWriter output stream.
        /// </summary>
        /// <param name="s">The string to encode.</param>
        /// <param name="output">The TextWriter output stream that contains the encoded string.</param>
        void HtmlEncode(string s, TextWriter output);

        /// <summary>
        /// Returns the physical file path that corresponds to the specified virtual path on the Web server.
        /// </summary>
        /// <param name="path">The virtual path of the Web server.</param>
        /// <returns>The physical file path that corresponds to path.</returns>
        string MapPath(string path);

        /// <summary>
        /// For the current request, terminates execution of the current page and starts execution of a new page by using the specified URL path of the page.
        /// </summary>
        /// <param name="path">The URL path of the new page on the server to execute.</param>
        void Transfer(string path);

        /// <summary>
        /// Terminates execution of the current page and starts execution of a new request by using a custom HTTP handler that implements the IHttpHandler interface and specifies whether to clear the QueryString and Form collections.
        /// </summary>
        /// <param name="handler">The HTTP handler that implements the IHttpHandler to transfer the current request to.</param>
        /// <param name="preserveForm">true to preserve the QueryString and Form collections; false to clear the QueryString and Form collections.</param>
        void Transfer(IHttpHandler handler, bool preserveForm);

        /// <summary>
        /// Terminates execution of the current page and starts execution of a new page by using the specified URL path of the page. Specifies whether to clear the QueryString and Form collections.
        /// </summary>
        /// <param name="path">The URL path of the new page on the server to execute.</param>
        /// <param name="preserveForm">true to preserve the QueryString and Form collections; false to clear the QueryString and Form collections.</param>
        void Transfer(string path, bool preserveForm);

        /// <summary>
        /// Performs an asynchronous execution of the specified URL.
        /// </summary>
        /// <param name="path">The URL path of the new page on the server to execute.</param>
        void TransferRequest(string path);

        /// <summary>
        /// Performs an asynchronous execution of the specified URL and preserves query string parameters.
        /// </summary>
        /// <param name="path">The URL path of the new page on the server to execute.</param>
        /// <param name="preserveForm">true to preserve the QueryString and Form collections; false to clear the QueryString and Form collections.</param>
        void TransferRequest(string path, bool preserveForm);

        /// <summary>
        /// Performs an asynchronous execution of the specified URL using the specified HTTP method and headers.
        /// </summary>
        /// <param name="path">The URL path of the new page on the server to execute.</param>
        /// <param name="preserveForm">true to preserve the QueryString and Form collections; false to clear the QueryString and Form collections.</param>
        /// <param name="method">The HTTP method to use in the execution of the new request.</param>
        /// <param name="headers">A NameValueCollection of request headers for the new request.</param>
        void TransferRequest(string path, bool preserveForm, string method, NameValueCollection headers);

        /// <summary>
        /// URL-decodes a string and returns the decoded string.
        /// </summary>
        /// <param name="s">The text string to decode.</param>
        /// <returns>The decoded text.</returns>
        string UrlDecode(string s);

        /// <summary>
        /// Decodes an HTML string received in a URL and sends the resulting output to a TextWriter output stream.
        /// </summary>
        /// <param name="s">The HTML string to decode.</param>
        /// <param name="output">The TextWriter output stream that contains the decoded string.</param>
        void UrlDecode(string s, TextWriter output);

        /// <summary>
        /// URL-encodes a string and returns the encoded string.
        /// </summary>
        /// <param name="s">The text to URL-encode.</param>
        /// <returns>The URL-encoded text.</returns>
        string UrlEncode(string s);

        /// <summary>
        /// URL-encodes a string and sends the resulting output to a TextWriter output stream.
        /// </summary>
        /// <param name="s">The text string to encode.</param>
        /// <param name="output">The TextWriter output stream that contains the encoded string.</param>
        void UrlEncode(string s, TextWriter output);

        /// <summary>
        /// URL-encodes the path section of a URL string and returns the encoded string.
        /// </summary>
        /// <param name="s">The text to URL-encode.</param>
        /// <returns>The URL encoded text.</returns>
        string UrlPathEncode(string s);

        #endregion
    }
}
